package vno.ky.seek
{
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.utils.getTimer;
	
	import vno.fux.*;
	import vno.ky.*;	
	public class Test extends Sprite
	{
		public function Test()
		{
			var background:Sprite=new Sprite();
			var wall:Shape=new Shape();
			var StartX:int;
			var StartY:int;
			var EndX:int;
			var EndY:int;
			var path:Deal=new Deal();
			var i:int;
			var sample:Vector.<Vector.<int>>=new Vector.<Vector.<int>>(150,true); 
			var count:int=1;
			var test=2;						//设置类型
			background.graphics.beginFill(0xff669900);
			background.graphics.drawRect(0,0,450,450);
			background.graphics.endFill();
			addChild(background);
			for(i=0;i<150;i++)
			{
				sample[i]=new Vector.<int>(150,true);
			}
			for(i=0;i<150;i++)
			{
				for(var j:int=0;j<150;j++)
				{
					sample[i][j]=0;
				}
			}
			for(i=0;i<150;i++)				//设置边界全为墙
			{
				sample[i][0]=1;
				sample[i][149]=1;
				sample[0][i]=1;
				sample[149][i]=1;
				drawwall(i,0);
				drawwall(i,149);
				drawwall(0,i);
				drawwall(149,i);
			}
			if(test==1)
			{	
				for(i=0;i<130;i++)					//设置墙
				{
					sample[10][i]=1;
					sample[30][i]=1;
					sample[50][i]=1;
					sample[100][i]=1;
					sample[120][i]=1
					drawwall(10,i);
					drawwall(30,i);
					drawwall(50,i);
					drawwall(100,i);
					drawwall(120,i);
				}
				for(i=20;i<100;i++)
				{
					sample[40][i]=1;
					drawwall(40,i);
				}
				for(i=50;i<90;i++)
				{
					sample[i][20]=1;
					sample[i][50]=1;
					drawwall(i,20);
					drawwall(50,i);
				}
			}
			if(test==2)
			{
				for(i=20;i<=100;i++)
				{
					sample[i][20]=1;
					sample[i][100]=1;
					sample[20][i]=1;
					sample[100][i]=1;
					drawwall(i,20);
					drawwall(i,100);
					drawwall(20,i);
					drawwall(100,i);
				}
			}
			this.stage.addEventListener(MouseEvent.CLICK,clickHandler);
			function clickHandler(evt:MouseEvent):void					//鼠标点击事件
			{
				if(count%2==1)
				{
					StartX=evt.stageX/3;
					StartY=evt.stageY/3;
					var rect:Shape=new Shape();
					rect.graphics.beginFill(0xff0000);
					rect.graphics.drawRect(evt.stageX,evt.stageY,3,3);
					rect.graphics.endFill();
					addChild(rect);
					background.addChild(rect);
					count++;
				}
				else
				{
					EndX=evt.stageX/3;
					EndY=evt.stageY/3;
					count++;
				}
				if(count%2==1)
				{
					
					path.set(sample);				//输入
					var currentTime=getTimer();
					var m:Array =path.seek(StartX,StartY,EndX,EndY).slice();						//输出数组为m或者path.seek（） 注释供测试用
					for(i=0;i<m.length;i++)
					{
						trace(m[i].pathX + "," + m[i].pathY);
					}
					trace("times:");
					trace(getTimer()-currentTime);
					trace("ms");
				}	
			}
			function drawwall(x:int,y:int):void
			{
				wall.graphics.beginFill(0x000000);
				wall.graphics.drawRect(x*3,y*3,3,3);
				wall.graphics.endFill();
				background.addChild(wall);
			}
		}
	}
}